package com.mp.tanlong;

import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;

/**
 * APP鐏拌壊淇濇椿
 * Created by fflin on 2016/4/23.
 */
public class GrayService extends Service {
	private final static int GRAY_SERVICE_ID = 1001;

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		//API < 18,姝ゆ柟娉曡兘鏈夋晥鍦伴殣钘弉otification鐨勫浘鏍�
		if (Build.VERSION.SDK_INT < 18) {
			startForeground(GRAY_SERVICE_ID, new Notification());
		} else {
			Intent intent1 = new Intent(this, GrayInnerService.class);
			startService(intent1);
			startForeground(GRAY_SERVICE_ID, new Notification());
		}
		return super.onStartCommand(intent, flags, startId);
	}


	//缁橝PI >= 18 鐨勫钩鍙颁笂鍋氱伆鑹蹭繚鎶ゆ墜娈�
	public class GrayInnerService extends Service {
		@Override
		public IBinder onBind(Intent intent) {
			return null;
		}


		@Override
		public int onStartCommand(Intent intent, int flags, int startId) {
			startForeground(GRAY_SERVICE_ID, new Notification());
			stopForeground(true);
			stopSelf();

			return super.onStartCommand(intent, flags, startId);
		}
	}


}
